﻿Imports System.Text.RegularExpressions
Imports System.Globalization

Module modGlobal
    Public Function FindBetween(ByVal src As String, ByVal start As String, ByVal [end] As String, Optional ByVal [case] As Boolean = True) As String()
        Dim s_case = If([case], "(?i)", "")
        Dim pat As String = "(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\|\\)"
        start = Regex.Replace(start, pat, "\$1")
        [end] = Regex.Replace([end], pat, "\$1")
        If start = "" Then start = "\A"
        If [end] = "" Then [end] = "\z"
        Dim a_ret As MatchCollection = Regex.Matches(src, "(?s)" & s_case & start & "(.*?)" & [end], 3)
        Dim l As New List(Of String)
        For Each m As Match In a_ret
            l.Add(m.Groups(1).Value)
        Next
        Return l.ToArray()
    End Function

    Public Function CDouble(ByVal str As String) As Double
        Return Double.Parse(If(str = "", "-1", str.Replace(",", ".")), New CultureInfo("en-US"))
    End Function

    Public Function DoubleCompare(ByVal d1 As Double, ByVal d2 As Double) As Integer
        Return If(d1 > d2, 1, If(d1 = d2, 0, -1))
    End Function
End Module
